package com.lonty.vote.controller;

import com.lonty.vote.api.Result;
import com.lonty.vote.api.ResultCode;
import com.lonty.vote.service.VoteContentService;
import com.lonty.vote.vo.VoteContentVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

/**
 * @Author 陈璇
 * @Date 2020/5/25 10:14
 * @Version 1.0
 */
@RestController
@RequestMapping("app/voteContent")
@Validated
@Api(tags = "投票内容接口", produces = "application/json")
public class VoteContentController {

    @Resource
    private VoteContentService voteContentService;

    @ApiOperation(value = "保存投票内容", httpMethod = "POST")
    @PostMapping("saveVoteContent")
    public Result saveVoteContent(VoteContentVo voteContentVo){
        if(voteContentService.saveVoteContent(voteContentVo)){
            return Result.builder().build();
        }
        return Result.builder(ResultCode.OPERATION_ERROR).build();
    }

    @ApiOperation(value = "获取投票内容", httpMethod = "GET")
    @GetMapping("getVoteContent")
    public Result getVoteContent(){
        return Result.builder()
                .data(voteContentService.getVoteContent())
                .build();
    }

}
